package com.wcs.exam.dao.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcs.exam.common.base.page.SqlUtil;
import com.wcs.exam.dao.SysRoleDao;
import com.wcs.exam.dao.impl.mapper.SysRoleMapper;
import com.wcs.exam.dao.impl.mapper.entity.SysRole;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 角色信息 服务实现类
 *
 * @author wcs
 * @since 2024-07-06
 */
@Repository
public class SysRoleDaoImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleDao {

    @Override
    public <R> List<R> selectObjs(Wrapper<SysRole> wrapper, Class<R> classType) {
        List<Map<String, Object>> resultMaps = baseMapper.selectMaps(wrapper);
        if (CollectionUtil.isEmpty(resultMaps)) {
            return Collections.emptyList();
        }
        return BeanUtil.copyToList(resultMaps, classType);
    }

    @Override
    public Integer getMaxSort() {
        return lambdaQuery().orderByDesc(SysRole::getSort).last(SqlUtil.limitOne()).oneOpt().map(SysRole::getSort).orElse(0);
    }
}
